// UglyDancingCactus.as
// Copyright 2008 Keith Irwin.

/* This is the UglyDancingCactus.  It is a demonstration of how to use
   the ClickAnimateFurniture class.  There also exists a non-ugly dancing
   cactus which you can buy in the store on Whirled if
   you would like to simply have a nicer version of this.  The purpose
   of the ugly dancing cactus is so that you can learn about how to
   use the ClickAnimateFurniture class to make your own animated
   furniture.

   A quick note, this class and the ClickAnimateFurniture class are both
   created by me, Keith Irwin.  I do not now nor have I ever worked for
   Three Rings.  I did this just to be nice.  So, if you find this nifty
   and/or useful, I would appreciate it if you would do something nice for
   me to say thanks.  I would, for instance, appreciate donations of stuff
   in Whirled.

   Anyway, on to the learning.  For anyone who is new to programming,
   anything in between the slashes and stars or on a line following
   two slashes is a comment.  Comments are just there for you to read
   and do not affect the running of the program at all, so you can
   leave them out of your code or change them.
   It is generally a good idea to write some comments because that
   way if you come back to make some changes later, you'll have help
   figuring out what you're doing. */

/* Anyway, these next few lines are mandatory, so you'll want to copy
   them in your code. */

package {
 
import flash.display.Sprite;
import flash.display.DisplayObject;
import com.whirled.contrib.display.ClickAnimateFurniture;

/* Here we indicate that it is a SWF (i.e. Shockwave Flash) and
   give the width and height.  You should use the width and height
   of the images which you are using here. */
[SWF(width="100", height="200")]

/* Here we declare the ActionScript class. You should put the name
   of your own class instead of UglyDancingCactus.  The file has to
   have the same name as the class plus the ".as" ending.  We want
   it to extend ClickAnimateFurniture.  This means that as an
   extension of that class, we inherit all of its methods. */
public class UglyDancingCactus extends ClickAnimateFurniture
{
    /* It's also a good idea to also put the height and width here. */
    public static const WIDTH :int = 100;
    public static const HEIGHT :int = 200;

    /* This is where we include the image files.  The names here,
       like IMAGE01, are going to be used below, but aside from
       making each image have a different name, it doesn't really
       matter what you call them.
       There should be one set of these statements for each image
       you're planning to use. */
    [Embed(source="uglyDancingCactuslurd.png")]
        protected static const IMAGE01 : Class;
    [Embed(source="uglyDancingCactusluru.png")]
        protected static const IMAGE02 : Class;
    [Embed(source="uglyDancingCactusldru.png")]
        protected static const IMAGE03 : Class;
    [Embed(source="uglyDancingCactusldrd.png")]
        protected static const IMAGE04 : Class;

    /* Here I create some constants to represent the index numbers 
       for the different frames.
       The index number for the frame is going to be based on
       an Array that we create later, but since I'm going to
       create the Array in the same order that I listed the images
       above, I can know what the indexes will be.
       The first image is number 0 and then the numbers go up from
       there.
       LURD = Left arm Up, Right arm Down.
       Creating this constants isn't necessary, but it can help
       keep track of things because I can now use LURD instead of
       0, LURU instead of 1, and so forth. */
    private static const LURD : int = 0;
    private static const LURU : int = 1;
    private static const LDRU : int = 2;
    private static const LDRD : int = 3;

    /* Next we have our constructor.  This is what gets called when
       the furniture is created. */
    public function UglyDancingCactus ()
    {
	/* The first thing we do is to call the superclass's
	   constructor and pass it an array of DisplayObjects.
	   We set up above.  We have to tell it to treat
	   each image as a DisplayObject. */
        super(new Array
              ((new IMAGE01() as DisplayObject),
               (new IMAGE02() as DisplayObject),
               (new IMAGE03() as DisplayObject),
               (new IMAGE04() as DisplayObject)));

	/* Then we set up the animations. Each animation is
	   an array, but each frame within the animation is
	   an array of two numbers.  The first number is which
	   frame to show, the second number is how long, in
	   milliseconds, it should be displayed for. 
	   Remember that 1000 milliseconds is 1 second,
	   so if you want a whole second, use 1000.  If you want
	   a half second, use 500, and so forth.
	   I use the constants I defined above for the frames,
	   but we could just use the numbers 0 through 3. */

	/* Our base animation only has one frame, so it's just
	   going to be a still image. */
	var baseAnimation:Array = new Array(new Array(LURD,100));

	/* The frames don't have to be on separate lines,
	   but I tend to space them out because I find it easier
	   to follow.  */
	var animation1:Array = new Array(new Array(LURU,500),
					 new Array(LDRD,200),
					 new Array(LURU,500),
					 new Array(LDRD,200),
					 new Array(LDRU,400),
					 new Array(LURD,400),
					 new Array(LDRU,400),
					 new Array(LURD,400),
					 new Array(LDRU,400),
					 new Array(LURD,400),
					 new Array(LURU,500),
					 new Array(LDRD,200),
					 new Array(LURU,500),
					 new Array(LDRD,200));
	var animation2:Array = new Array(new Array(LDRD,500),
					 new Array(LDRU,500),
					 new Array(LURU,500),
					 new Array(LURD,500),
					 new Array(LDRD,500),
					 new Array(LDRU,500),
					 new Array(LURU,500),
					 new Array(LURD,500),
					 new Array(LDRD,500),
					 new Array(LDRU,500),
					 new Array(LURU,500),
					 new Array(LURD,500));
	var animation3:Array = new Array(new Array(LURD,500),
					 new Array(LDRD,100),
					 new Array(LURD,500),
					 new Array(LDRD,100),
					 new Array(LURD,500),
					 new Array(LDRU,500),
					 new Array(LDRD,100),
					 new Array(LDRU,500),
					 new Array(LDRD,100),
					 new Array(LDRU,500),
					 new Array(LURD,500),
					 new Array(LDRD,100),
					 new Array(LURD,500),
					 new Array(LDRD,100),
					 new Array(LURD,500),
					 new Array(LDRU,500),
					 new Array(LDRD,100),
					 new Array(LDRU,500),
					 new Array(LDRD,100),
					 new Array(LDRU,500),
					 new Array(LURD,500),
					 new Array(LDRD,100),
					 new Array(LURD,500),
					 new Array(LDRD,100),
					 new Array(LURD,500),
					 new Array(LDRU,500),
					 new Array(LDRD,100),
					 new Array(LDRU,500),
					 new Array(LDRD,100),
					 new Array(LDRU,500));
	var animation4:Array = new Array(new Array(LURD,200),
					 new Array(LDRU,200),
					 new Array(LURU,1000),
					 new Array(LDRD,100),
					 new Array(LURU,1000),
					 new Array(LURD,200),
					 new Array(LDRU,200),
					 new Array(LURU,1000),
					 new Array(LDRD,100),
					 new Array(LURU,1000),
					 new Array(LURD,200),
					 new Array(LDRU,200));

	/* Then we put all the animations together in one big array. 
	   and call setAnimations. */
        setAnimations(new Array(baseAnimation,
				animation1,
				animation2,
				animation3,
				animation4));

	/* I want him do chose a dance to do randomly each time he is
	   clicked.  If you want him to do each dance once before
	   repeating, then this can be changed to false. */
        randomizeAnimations = true;

	/* And we want him to go back to his base animation, which
	   in this case is just sitting there.  If you want him
	   to continue doing one animation until he's clicked,
	   you can change this to disable or just leave it out. */
	enableReturnToBaseAnimation();

	/* If we want the cursor to turn into a hand when it hovers over
           the piece of furniture, we can set buttonMode to true.
           This helps people know that they can click on it. */
        buttonMode = true;

	/* Now that everything is all set up, we can tell it to begin
	   animating and responding to clicks. */
        start();
    }
    
}
}
/* And that's it. */